package ar.edu.unlam.tpfinal.struts.actions;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import ar.edu.unlam.tpfinal.service.TransactionService;
import ar.edu.unlam.tpfinal.struts.forms.TransactionForm;

public class TransactionAction extends Action {
	
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
								 HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServlet().getServletContext());
		TransactionService ts = (TransactionService) context.getBean("transactionService");
		List<TransactionForm> transactionForm = ts.listTransaction();
		
		request.setAttribute("transactionList", transactionForm);
		request.setAttribute("errors", "");
		return mapping.findForward("success");
	}
}
